package br.com.jmed.util;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator("br.com.jmed.util.AutoCompleteValidator")
public class AutoCompleteValidator implements Validator {

	public void validate(FacesContext context, UIComponent component,Object value) throws ValidatorException {
		try {
			String valor = (String) value;
			String[] tokens = valor.split(" - ");
			Integer.parseInt(tokens[0]);
		}catch (Exception e3){
			FacesMessage msg = new FacesMessage("Valor inválido no campo "+component.getId());
			throw new ValidatorException(msg);
		}
		
	}

}
